package cn.itsource.fallback;

import cn.itsource.api.CustomerApi;
import cn.itsource.pojo.result.CustomerInfo;
import cn.itsource.result.JSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CustomerApiFallback implements FallbackFactory<CustomerApi> {
    @Override
    public CustomerApi create(Throwable cause) {

        return new CustomerApi(){
            @Override
            public JSONResult hasFine(Long customerId) {
                log.error("CustomerApi 调用失败：{}", cause.getMessage(), cause);
                return JSONResult.error("服务调用失败["+cause.getMessage()+"]");
            }

            @Override
            public JSONResult<CustomerInfo> get(Long customerId) {
                log.error("CustomerApi 调用失败：{}", cause.getMessage(), cause);
                return JSONResult.error("服务调用失败["+cause.getMessage()+"]");
            }


        };

    }
}
